package cn.slg.module.system.controller.pk;

import cn.slg.module.system.controller.pk.vo.FightGroupVO;
import cn.slg.module.system.controller.pk.vo.PKVO;
import cn.slg.module.system.controller.pk.vo.WuJiangVO;
import cn.slg.module.system.dal.dataobject.group.Group;
import cn.slg.module.system.dal.dataobject.wujiang.WuJiangDO;
import cn.slg.module.system.service.pk.bo.PKBO;
import cn.slg.module.system.service.pk.PKService;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.beans.BeanProperty;

@RestController
@RequestMapping("/system/pk")
public class PKController {

    @Resource
    private PKService pKService;


    @PostMapping("/put")
    public void towGroupPk(@RequestBody PKVO pkvo) {
        PKBO pkbo = new PKBO();
        pkbo.setFirstGroup(new Group());
        pkbo.setSecondGroup(new Group());
        Group firstGroup = pkbo.getFirstGroup();
        Group secondGroup = pkbo.getSecondGroup();

        FightGroupVO pkvoFirstGroup = pkvo.getFirstGroup();
        FightGroupVO pkvoSecondGroup = pkvo.getSecondGroup();

        firstGroup.setShiQi(pkvoFirstGroup.getShiQi());
        firstGroup.setBingZhong(pkvoFirstGroup.getBingZhong());
        firstGroup.setAttackerOrDefense(pkvoFirstGroup.getAttackerOrDefense());

        secondGroup.setShiQi(pkvoSecondGroup.getShiQi());
        secondGroup.setBingZhong(pkvoSecondGroup.getBingZhong());
        secondGroup.setAttackerOrDefense(pkvoSecondGroup.getAttackerOrDefense());

        // 初始化两队所有武将
        for (WuJiangVO vo : pkvoFirstGroup.getFightGroup()) {
            Integer id = vo.getId();
            WuJiangDO wuJiangDO = new WuJiangDO();
            wuJiangDO.setId(id);
            firstGroup.getAllGroup().add(wuJiangDO);
        }

        for (WuJiangVO vo : pkvoSecondGroup.getFightGroup()) {
            Integer id = vo.getId();
            WuJiangDO wuJiangDO = new WuJiangDO();
            wuJiangDO.setId(id);
            secondGroup.getAllGroup().add(wuJiangDO);
        }

        pKService.pk(pkbo);

    }
}
